package com.dongdongshop.Service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.data.Page;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
@org.springframework.stereotype.Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private TbBrandMapper tbBrandMapper;

    @Override
    public List<TbBrand> brandList() {
        return tbBrandMapper.selectByExample(null);
    }

    @Override
    public TbBrand getBrandById(Long id) {
        return tbBrandMapper.selectByPrimaryKey(id);
    }

    @Override
    public Page<TbBrand> brandPage(Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<TbBrand> list = tbBrandMapper.selectByExample(null);
        PageInfo<TbBrand> page = new PageInfo<>(list);
        return new Page<TbBrand>(page.getPageNum(),page.getPageSize(),page.getTotal(),page.getPages(),page.getList());
    }

    @Override
    public Boolean addModal(TbBrand tbBrand) {
        Integer i = tbBrandMapper.insert(tbBrand);
        return i > 0;
    }

    @Override
    public Boolean updateModal(TbBrand tbBrand) {
        Integer i = tbBrandMapper.updateByPrimaryKeySelective(tbBrand);
        return i > 0;
    }

    @Override
    public Boolean deleteById(Long id) {
        Integer i = tbBrandMapper.deleteByPrimaryKey(id);
        return i > 0;
    }

    @Override
    public Boolean deleteInfo(Integer[] id) {
        return tbBrandMapper.deleteInfo(id);
    }
}
